home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qpoint.h.z / qpoint.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.2 KB  |  186 lines

  1. /****************************************************************************
  2. ** $Id: qpoint.h,v 2.4 1998/07/03 00:09:37 hanord Exp $
  3. **
  4. ** Definition of QPoint class
  5. **
  6. ** Created : 931028
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QPOINT_H
  25. #define QPOINT_H
  26.  
  27. #ifndef QT_H
  28. #include "qwindowdefs.h"
  29. #endif // QT_H
  30.  
  31. #if defined(QPOINT_C) || defined(DEBUG)
  32. #define QPOINT_DEBUG
  33. #endif
  34.  
  35.  
  36. class QPoint
  37. {
  38. public:
  39.     QPoint()    {}
  40.     QPoint( int xpos, int ypos );
  41.  
  42.     bool   isNull()    const;
  43.  
  44.     int       x()        const;
  45.     int       y()        const;
  46.     void   setX( int x );
  47.     void   setY( int y );
  48.  
  49.     QCOORD &rx();
  50.     QCOORD &ry();
  51.  
  52.     QPoint &operator+=( const QPoint &p );
  53.     QPoint &operator-=( const QPoint &p );
  54.     QPoint &operator*=( int c );
  55.     QPoint &operator*=( double c );
  56.     QPoint &operator/=( int c );
  57.     QPoint &operator/=( double c );
  58.  
  59.     friend inline bool     operator==( const QPoint &, const QPoint & );
  60.     friend inline bool     operator!=( const QPoint &, const QPoint & );
  61.     friend inline QPoint operator+( const QPoint &, const QPoint & );
  62.     friend inline QPoint operator-( const QPoint &, const QPoint & );
  63.     friend inline QPoint operator*( const QPoint &, int );
  64.     friend inline QPoint operator*( int, const QPoint & );
  65.     friend inline QPoint operator*( const QPoint &, double );
  66.     friend inline QPoint operator*( double, const QPoint & );
  67.     friend inline QPoint operator-( const QPoint & );
  68. #if defined(QPOINT_DEBUG)
  69.     friend      QPoint operator/( const QPoint &, int );
  70.     friend      QPoint operator/( const QPoint &, double );
  71. #else
  72.     friend inline QPoint operator/( const QPoint &, int );
  73.     friend inline QPoint operator/( const QPoint &, double );
  74. #endif
  75.  
  76. private:
  77. #if defined(_OS_MAC_)
  78.     QCOORD yp;
  79.     QCOORD xp;
  80. #else
  81.     QCOORD xp;
  82.     QCOORD yp;
  83. #endif
  84. };
  85.  
  86.  
  87. /*****************************************************************************
  88.   QPoint stream functions
  89.  *****************************************************************************/
  90.  
  91. QDataStream &operator<<( QDataStream &, const QPoint & );
  92. QDataStream &operator>>( QDataStream &, QPoint & );
  93.  
  94.  
  95. /*****************************************************************************
  96.   QPoint inline functions
  97.  *****************************************************************************/
  98.  
  99. inline QPoint::QPoint( int xpos, int ypos )
  100. { xp=(QCOORD)xpos; yp=(QCOORD)ypos; }
  101.  
  102. inline bool QPoint::isNull() const
  103. { return xp == 0 && yp == 0; }
  104.  
  105. inline int QPoint::x() const
  106. { return xp; }
  107.  
  108. inline int QPoint::y() const
  109. { return yp; }
  110.  
  111. inline void QPoint::setX( int x )
  112. { xp = (QCOORD)x; }
  113.  
  114. inline void QPoint::setY( int y )
  115. { yp = (QCOORD)y; }
  116.  
  117. inline QCOORD &QPoint::rx()
  118. { return xp; }
  119.  
  120. inline QCOORD &QPoint::ry()
  121. { return yp; }
  122.  
  123. inline QPoint &QPoint::operator+=( const QPoint &p )
  124. { xp+=p.xp; yp+=p.yp; return *this; }
  125.  
  126. inline QPoint &QPoint::operator-=( const QPoint &p )
  127. { xp-=p.xp; yp-=p.yp; return *this; }
  128.  
  129. inline QPoint &QPoint::operator*=( int c )
  130. { xp*=(QCOORD)c; yp*=(QCOORD)c; return *this; }
  131.  
  132. inline QPoint &QPoint::operator*=( double c )
  133. { xp=(QCOORD)(xp*c); yp=(QCOORD)(yp*c); return *this; }
  134.  
  135. inline bool operator==( const QPoint &p1, const QPoint &p2 )
  136. { return p1.xp == p2.xp && p1.yp == p2.yp; }
  137.  
  138. inline bool operator!=( const QPoint &p1, const QPoint &p2 )
  139. { return p1.xp != p2.xp || p1.yp != p2.yp; }
  140.  
  141. inline QPoint operator+( const QPoint &p1, const QPoint &p2 )
  142. { return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
  143.  
  144. inline QPoint operator-( const QPoint &p1, const QPoint &p2 )
  145. { return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
  146.  
  147. inline QPoint operator*( const QPoint &p, int c )
  148. { return QPoint(p.xp*c, p.yp*c); }
  149.  
  150. inline QPoint operator*( int c, const QPoint &p )
  151. { return QPoint(p.xp*c, p.yp*c); }
  152.  
  153. inline QPoint operator*( const QPoint &p, double c )
  154. { return QPoint((QCOORD)(p.xp*c), (QCOORD)(p.yp*c)); }
  155.  
  156. inline QPoint operator*( double c, const QPoint &p )
  157. { return QPoint((QCOORD)(p.xp*c), (QCOORD)(p.yp*c)); }
  158.  
  159. inline QPoint operator-( const QPoint &p )
  160. { return QPoint(-p.xp, -p.yp); }
  161.  
  162. //
  163. // The QPoint functions below are inline if DEBUG is not defined.
  164. // The debug implementation in qpoint.cpp checks c and gives a warning
  165. // before dividing by zero.
  166. //
  167.  
  168. #if !defined(QPOINT_DEBUG)
  169.  
  170. inline QPoint &QPoint::operator/=( int c )
  171. { xp/=(QCOORD)c; yp/=(QCOORD)c; return *this; }
  172.  
  173. inline QPoint &QPoint::operator/=( double c )
  174. { xp=(QCOORD)(xp/c); yp=(QCOORD)(yp/c); return *this; }
  175.  
  176. inline QPoint operator/( const QPoint &p, int c )
  177. { return QPoint(p.xp/c, p.yp/c); }
  178.  
  179. inline QPoint operator/( const QPoint &p, double c )
  180. { return QPoint((QCOORD)(p.xp/c), (QCOORD)(p.yp/c)); }
  181.  
  182. #endif // no-debug inline functions
  183.  
  184.  
  185. #endif // QPOINT_H
  186.